import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { DictDataService } from "@service/system/dictData.service";
import { ListDictDataDTO, CreateDictDataDTO, UpdateDictDataDTO } from "@dto/system/dictData.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/system/dict/data')
export class PostController {
  @Inject()
  dictDataService: DictDataService;

  // 获取列表
  @Auth('system:dict:list')
  @Get('/list')
  async list(@Query() queryParams: ListDictDataDTO) {
    return await this.dictDataService.list(queryParams);
  }

  // 新增
  @Auth('system:dict:add')
  @Log({ title: '字典数据', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() dictData: CreateDictDataDTO) {
    return await this.dictDataService.create(dictData);
  }

  // 删除
  @Auth('system:dict:remove')
  @Log({ title: '字典数据', businessType: BusinessType.REMOVE })
  @Del('/:dictCode')
  async delete(@Param('dictCode') dictCode: string) {
    return await this.dictDataService.delete(dictCode);
  }

  // 修改
  @Auth('system:dict:edit')
  @Log({ title: '字典数据', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() dictData: UpdateDictDataDTO) {
    return await this.dictDataService.update(dictData);
  }

  // 获取详情
  @Auth('system:dict:query')
  @Get('/:dictCode')
  async get(@Param('dictCode') dictCode: number) {
    return await this.dictDataService.detail(dictCode);
  }

  // 导出
  @Auth('system:dict:export')
  @Log({ title: '字典数据', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Query() queryParams: ListDictDataDTO) {
    return await this.dictDataService.export(queryParams);
  }

  // 根据字典类型type，查询字典数据信息
  @Get('/type/:dictType')
  async typeDataList(@Param('dictType') dictType: string) {
    return await this.dictDataService.getDictDataByType(dictType);
  }
}
